package com.igbeok.miscellaneous.concurrency.hemberg2;

public class Cooker implements Runnable {
	private Waiter waiter;
	private Pool pool;

	public Cooker(Waiter waiter, Pool pool) {
		this.waiter = waiter;
		this.pool = pool;
	}

	@Override
	public void run() {
		while (true) {
			if (!pool.isFull()) {
				synchronized (waiter) {
					pool.push(new Hemberg());
					System.out.println("Cooker: Hember is ok! notifyAll");
					waiter.notifyAll();
				}
			}else{
				synchronized (pool) {
					System.out.println("Cooker: pool is full! wait!");
					try {
						pool.wait();
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
	}

}
